package com.brkj.main;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.annotation.view.ViewInject;
import com.brkj.httpInterface.BaseAjaxParams;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.brkj.main.R;
import com.brkj.httpInterface.HttpInterface.HIF_FindPassWord;
import com.brkj.util.JsonUtil;
import com.brkj.util.MyAjaxCallBack;
import com.brkj.util.view.BaseActivity;
import com.brkj.util.view.WidgetAnim;

public class FindPassWordAcivity extends BaseActivity{

	@ViewInject(id=R.id.UserAcount) EditText UserAcount;
	@ViewInject(id=R.id.PhontNum) EditText PhontNum;
	@ViewInject(id=R.id.Email) EditText Email;
	@ViewInject(id=R.id.submit, click="submit") Button submit;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setAnimType(BaseActivity.RIGHT_ENTER_LEFT_EXT);
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.find_password);
		
		setReturnBtn();
		setActivityTitle("找回密码");
		
	}

	public void submit(View v){
		
		if(WidgetAnim.checkIfEmpty(this, UserAcount) 
			||WidgetAnim.checkIfEmpty(this, PhontNum)
			||WidgetAnim.checkIfEmpty(this, Email)){
			
			return;
		}
		
		BaseAjaxParams params = new BaseAjaxParams();
		  params.put(HIF_FindPassWord.params.UserName, UserAcount.getText().toString());
		  params.put(HIF_FindPassWord.params.PhoneNum, PhontNum.getText().toString());
		  params.put(HIF_FindPassWord.params.Email, Email.getText().toString());


		  FinalHttp fh = new FinalHttp();
		  fh.post(HIF_FindPassWord.address, params, new MyAjaxCallBack<Object>(this){

			@Override
			public void onSuccess(Object t) {
				super.onSuccess(t);
				
				HIF_FindPassWord.result result = 
						JsonUtil.fromJson((String) t, HIF_FindPassWord.result.class);
				
				if(result.getResult() == 0){
					showToast(result.getReason());
				}else if(result.getResult() == 1){
					showToast("已提交，请等待管理员处理！");
				}
			}

		        
		  });
	}
}
